'use strict'
// Template version: 1.1.1
// see http://vuejs-templates.github.io/webpack for documentation.

const path = require('path')
const os = require('os')

//获取命令行环境变量
const argEnv = require('yargs').argv.env
const argInterface = require('yargs').argv.interface

function getLocalIp() {
    var osNet = os.networkInterfaces();
    for (var devName in osNet) {
        var iface = osNet[devName];
        for (var i = 0; i < iface.length; i++) {
            var alias = iface[i];
            if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
                return alias.address;
            }
        }
    }
}

//当前电脑ip
var localIp = getLocalIp();
console.log(localIp)
module.exports = {

    //测试环境、预生产、生产打包所用
    build: {
        env: require('./prod.env'),
        index: path.resolve(__dirname, '../dist/index.html'),
        assetsRoot: path.resolve(__dirname, '../dist'),
        assetsSubDirectory: 'static',
        productionSourceMap: false,
        productionGzip: true,
        productionGzipExtensions: ['js', 'css'],
        bundleAnalyzerReport: process.env.npm_config_report,

        //根据不同环境添加埋点域名
        mdDomain: (function () {
            if (argEnv == 4) {
                //生产
                return 'https://dc.chtwm.com'
            } else if (argEnv == 3 || argEnv == "3_b") {
                //预生产
                return 'https://dc.uata.haomalljf.com'
            } else if (argEnv == 2) {
                //测试
                return 'https://dc.qasa.chtwm.com'
            }
        })(),

        //根据不同环境添加cdn域名
        assetsPublicPath: (function () {
            if (argEnv == 4) {
                //生产
                return 'https://ac.chtfund.com/'
            } else if (argEnv == 3) {
                //预生产
                return 'https://ac.haomaojf.com/'
            } else if (argEnv == 2) {
                //测试
                return 'https://ac-qasa.chtfundtest.com/'
            } else if (argEnv == '2_b') {
                //测试2_b环境
                return 'https://htjj-app-h5-test-b.chtfundtest.com/'
            } else if (argEnv == 1) {
                //开发环境
                return 'https://h5.htjf4.com/'
            } else {
                return '/'
            }
        })(),
    },

    //开发环境打包所用
    dev: {
        host: '0,0,0,0',
        env: require('./dev.env'),
        port: process.env.PORT || 8002,
        https: false,
        autoOpenBrowser: true,
        assetsSubDirectory: 'static',

        assetsPublicPath: '/',
        mdDomain: 'http://localhost:9099',
        proxyTable: (function () {
            var obj = {
                '/web': {
                    // target: 'http://' + localIp + ':8509', //本地环境
                    target: 'https://mall.faw-vw.com',
                    //  target: 'https://h5.chtwmlocal.com',//股份-联调环境
                    // target:'https://h5.chtwmtest.com',//股份-测试环境
                    // target = 'http://172.16.117.111:8080', // 本地环境-模拟数据
                    changeOrigin: true,
                    secure: false,
                },
            };
            if (argInterface == 0) {
                // 模拟数据
                obj['/web'].target = 'http://' + localIp + ':8509'; // 本地环境-模拟数据
                // obj['/web'].target = 'https://h5.chtfundtest.com'; // 本地环境-模拟数据
                return obj
            } else if (argInterface == 1) {
                //本地连联调环境
                // obj['/web'].target = 'http://172.16.188.228:8080';   // 程珑电脑ip
                // obj['/web'].target = 'http://172.16.187.129:8080';   // 张亚楠电脑IP
                // obj['/web'].target = 'http://172.16.188.118:8080';   // 胡亚宁电脑IP
                obj['/web'].target = 'https://h5.htjf4.com';
                return obj
            } else if (argInterface == 2) {
                //本地连测试环境
                obj['/web'].target = 'https://ac-qasa.chtfundtest.com';
                obj['/web'].target = 'https://h5.chtfundtest.com';
                 obj['/web'].target = 'https://hlhapp-qasa.chtfund.com'; 
                return obj
            } else if (argInterface == '2_b') {
                //本地连测试环境
                obj['/web'].target = 'https://htjj-app-h5-test-b.chtfundtest.com';
                return obj
            } else if (argInterface == 3) {
                //本地连预生产环境
                obj['/web'].target = 'https://h5.haomaojf.com';
                return obj
            } else if (argInterface == '3_b') {
                //本地连预生产环境
                obj['/web'].target = 'http://htjj-app-h5.haomaojf.com/';
                return obj
            } else if (argInterface == 4) {
                //本地连预生产环境
                obj['/web'].target = 'https://h5.chtfund.com';
                return obj
            }

        })(),
        cssSourceMap: false
    },
    chainWebpack: config => {
    		config.resolve.alias.set('static',resolve('/src/static'))
    	}
}
